/**
 * 
 */
package com.nari.heatshare.action;

import java.io.FileInputStream;

import org.apache.struts2.json.annotations.JSON;

import com.nari.coreframe.action.struts2.JSONActionSupport;
import com.nari.ftpclient.business.IRemoteFileManage;
import com.nari.heatshare.model.IGprsUploadTrace;
import com.nari.heatshare.service.IGprsUploadTraceService;

/**
 * 
 * @author Xiaopeng
 * @date 2014-5-8
 */
public class GprsUploadTraceAction extends JSONActionSupport {
	private static final long serialVersionUID = -3381281747211386421L;
	private IGprsUploadTraceService iGprsUploadTraceService;
	private String uploadTraceUID;
	private IGprsUploadTrace gprsUploadTrace;
	//下载FTP远程文件
	private IRemoteFileManage iRemoteFileManage;
	private String tempFilePath;
	
	/**
	 * 下载批次上传的痕迹文件
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-5-8
	 */
	public String downloadUploadTrace() throws Exception {
		if(uploadTraceUID!=null && !"".equals(uploadTraceUID)) {
			this.gprsUploadTrace = iGprsUploadTraceService.queryEntityById(uploadTraceUID);
		}
		//痕迹信息不存在，返回异常信息
		if(gprsUploadTrace == null) {
			return "exception";
		}
		//下载FTP远程文件并构造输出流
		this.rmsg = iRemoteFileManage.downloadFile("", gprsUploadTrace.getSvFilename()+"."+gprsUploadTrace.getFileType(), this.tempFilePath);
		if(rmsg.isSuccess()) {
			this.setTargetFile(new FileInputStream(this.tempFilePath+"/"+gprsUploadTrace.getSvFilename()+"."+gprsUploadTrace.getFileType()));
		}
//		this.setTargetFile(new FileInputStream(gprsUploadTrace.getDiskID()+"/"+gprsUploadTrace.getSavePath()));
		//设置模板名称
		this.setOutputFileName(gprsUploadTrace.getOrFilename()+"."+gprsUploadTrace.getFileType());
		return "downloadTraceFile";
	} 

	/**
	 * @return the iGprsUploadTraceService
	 */
	@JSON(serialize=false)
	public IGprsUploadTraceService getiGprsUploadTraceService() {
		return iGprsUploadTraceService;
	}

	/**
	 * @param iGprsUploadTraceService the iGprsUploadTraceService to set
	 */
	public void setiGprsUploadTraceService(
			IGprsUploadTraceService iGprsUploadTraceService) {
		this.iGprsUploadTraceService = iGprsUploadTraceService;
	}

	/**
	 * @return the uploadTraceUID
	 */
	public String getUploadTraceUID() {
		return uploadTraceUID;
	}

	/**
	 * @param uploadTraceUID the uploadTraceUID to set
	 */
	public void setUploadTraceUID(String uploadTraceUID) {
		this.uploadTraceUID = uploadTraceUID;
	}

	/**
	 * @return the gprsUploadTrace
	 */
	public IGprsUploadTrace getGprsUploadTrace() {
		return gprsUploadTrace;
	}

	/**
	 * @param gprsUploadTrace the gprsUploadTrace to set
	 */
	public void setGprsUploadTrace(IGprsUploadTrace gprsUploadTrace) {
		this.gprsUploadTrace = gprsUploadTrace;
	}

	/**
	 * @return the iRemoteFileManage
	 */
	public IRemoteFileManage getiRemoteFileManage() {
		return iRemoteFileManage;
	}

	/**
	 * @param iRemoteFileManage the iRemoteFileManage to set
	 */
	public void setiRemoteFileManage(IRemoteFileManage iRemoteFileManage) {
		this.iRemoteFileManage = iRemoteFileManage;
	}

	/**
	 * @return the tempFilePath
	 */
	public String getTempFilePath() {
		return tempFilePath;
	}

	/**
	 * @param tempFilePath the tempFilePath to set
	 */
	public void setTempFilePath(String tempFilePath) {
		this.tempFilePath = tempFilePath;
	}
	
}
